﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DAL;
namespace UI.UserInfo
{
    public partial class UserInfo :Form
    {
    
        public void  reloadDataTable()
        {
            DataTable table=new DataTable();
            table = DAL.UserServer.staff().Tables[0];
           skinDataGridView1.DataSource = table;
        }
        public UserInfo()
        {
            InitializeComponent();
        }

        private void UserInfo_Load(object sender, EventArgs e)
        {
            this.FormBorderStyle = FormBorderStyle.None;
            //设置一行选中
            skinDataGridView1.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
            /*   DataTable dt = new DataTable();
               DataColumn dc = new DataColumn("员工");
               DataColumn dc2 = new DataColumn("员工编号", Type.GetType("System.String"));
               dt.Columns.Add(dc);
               dt.Columns.Add(dc2);
               DataRow row;
               row = dt.NewRow();
               row["员工"] = "1";
               row["员工编号"] = "1000";
               dt.Rows.Add(row);
               row = dt.NewRow();
               row["员工"] = "2";
               row["员工编号"]="2200";
               dt.Rows.Add(row);
                * */
            DataTable table = new DataTable();
            table = DAL.UserServer.staff().Tables[0];
            skinDataGridView1.DataSource = table;
        }

        private void 查看员工信息ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            //获取当前选中行 的""列的值
            object obj=skinDataGridView1.CurrentRow.Cells["员工编号"].Value;
            if (obj == null)
            {
                MessageBox.Show("你没有选择行！");
                return;
            }
           // int staffid = Convert.ToInt32(obj);
            Model.UserInfo uin = new Model.UserInfo();
            uin.Uid = Convert.ToInt32(obj); 

            uin = BLL.UserManager.staff_2(uin);
          // MessageBox.Show(uin.Birthday);
            UserInfoDetail udet = new UserInfoDetail();
            udet.parUserInfo = this;
            udet.uinfo = uin;
            udet.Show();
        }

        private void 添加员工ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            addnewUser add = new addnewUser();
            add.uInfo = this;
            add.Show();
        }

        private void 删除员工ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Model.UserInfo uf = new Model.UserInfo();
            int uid=Convert.ToInt32(skinDataGridView1.CurrentRow.Cells["员工编号"].Value);
            uf.Uid=uid;
            if (MessageBox.Show("是否删除", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Error) == DialogResult.OK)
            {
                BLL.UserManager.departjob_delete(uf);
                reloadDataTable();  
            }
            else 
            {
                    
            }
            
        }

        private void btn_search_Click(object sender, EventArgs e)
        {
            Model.UserInfo user = new Model.UserInfo();
            if (textboxsearch.Text == null || textboxsearch.Text == "")
            {
                MessageBox.Show("您没有输入");
                return;
            }
            if(UI.Global.isNumber(textboxsearch.Text)==false)
            {
                MessageBox.Show("你没有输入数字！");
                return ;
            }
            user.Uid = Convert.ToInt32(textboxsearch.Text);
            DataSet dt = BLL.UserManager.selectUserById(user);
            if (dt == null)
            {
                MessageBox.Show("没有查询到");
                return;
            }
            
            skinDataGridView1.DataSource = dt.Tables[0];

           
        }

        private void button1_Click(object sender, EventArgs e)
        {
            reloadDataTable();
        }

      
        
    }
}
